/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	AContractConverter.java
 * Created：		2016年9月5日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.contract.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.contract.AContract;
import com.thor.palmmall.spi.contract.SContract;

/**
 * @author wolv
 *
 */
public class AContractConverter implements Converter<SContract, AContract> {

  public static AContractConverter getInstance() {
    if (instance == null)
      instance = new AContractConverter();
    return instance;
  }

  private static AContractConverter instance;

  private AContractConverter() {
  }

  @Override
  public AContract convert(SContract source) {
    if (source == null)
      return null;

    AContract target = new AContract();
    target.setCode(source.getCode());
    target.setName(source.getName());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setUuid(source.getUuid());
    target.setTelephone(source.getTelephone());
    target.setPositions(new ArrayList<UCN>());
    target.getPositions().addAll(source.getPositions());
    target.setBeginDate(source.getBeginDate());
    target.setEndDate(source.getEndDate());
    target.setBizState(source.getBizState());
    target.setRentArea(source.getRentArea());
    target.setContractType(source.getContractType());
    return target;
  }

}
